package com.itboye.textileexpres.widget;

import com.itboye.textileexpres.R;

import android.R.integer;
import android.app.Dialog;
import android.content.Context;
import android.content.DialogInterface;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup.LayoutParams;
import android.view.Window;
import android.widget.RadioButton;
import android.widget.RadioGroup;

public class ImageDialog extends Dialog {
	public static String type = "goods";

	public ImageDialog(Context context) {
		super(context);
		// TODO Auto-generated constructor stub
	}

	public static class Builder {

		private Context context;
		private String title;
		private String message;
		private String yes;
		private String no;
		private View contentView;
		private DialogInterface.OnClickListener positiveButtonClickListener;
		private DialogInterface.OnClickListener negativeButtonClickListener;

		public Builder(Context context) {
			// TODO Auto-generated constructor stub
			this.context = context;
		}

		public Builder setMessage(String mag) {
			this.message = mag;
			return this;
		}

		public Builder setTitle(String mag) {
			this.title = mag;
			return this;
		}

		public Builder setContextView(View view) {
			this.contentView = view;
			return this;
		}

		public Builder setYes(int yes, DialogInterface.OnClickListener listener) {
			this.yes = (String) context.getText(yes);
			this.positiveButtonClickListener = listener;
			return this;

		}

		public Builder setYes(String yes,
				DialogInterface.OnClickListener listener) {
			this.yes = yes;
			this.positiveButtonClickListener = listener;
			return this;

		}

		public Builder setNo(String yes,
				DialogInterface.OnClickListener listener) {
			this.no = yes;
			this.negativeButtonClickListener = listener;
			return this;

		}

		public ImageDialog Create() {
			View view = LayoutInflater.from(context).inflate(
					R.layout.image_search_dialog, null);
			type = "goods";
			final ImageDialog dialog = new ImageDialog(context);
			dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
			dialog.addContentView(view, new LayoutParams(
					LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));

			RadioGroup group = (RadioGroup) view.findViewById(R.id.group);
			RadioButton search_bt = (RadioButton) group
					.findViewById(R.id.search_bt);
			RadioButton goods_bt = (RadioButton) group
					.findViewById(R.id.goods_bt);
			view.findViewById(R.id.search_bt);
			search_bt.setOnClickListener(new View.OnClickListener() {

				@Override
				public void onClick(View v) {
					// TODO Auto-generated method stub
					type = "search";
				}
			});
			goods_bt.setOnClickListener(new View.OnClickListener() {

				@Override
				public void onClick(View v) {
					// TODO Auto-generated method stub
					type = "goods";
				}
			});
			view.findViewById(R.id.yes).setOnClickListener(
					new View.OnClickListener() {

						@Override
						public void onClick(View v) {
							// TODO Auto-generated method stub
							positiveButtonClickListener.onClick(dialog,
									DialogInterface.BUTTON_POSITIVE);
						}

					});
			view.findViewById(R.id.no).setOnClickListener(
					new View.OnClickListener() {

						@Override
						public void onClick(View v) {
							// TODO Auto-generated method stub
							negativeButtonClickListener.onClick(dialog,
									DialogInterface.BUTTON_NEGATIVE);
						}
					});
			dialog.setContentView(view);
			return dialog;

		}
	}
}
